package com.straw.hat.common.util;

import io.netty.util.HashedWheelTimer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @author jianshan@byai.com
 * @date 2021/2/23 2:05 PM
 * describe:
 */
public enum  TimerUtil {



        /**
         * 枚举单例
         */
        INSTANCE;

        private final HashedWheelTimer wheelTimer;
        Logger logger = LoggerFactory.getLogger(TimerUtil.class);

        TimerUtil() {
            wheelTimer = new HashedWheelTimer(r -> {
                Thread t = new Thread(r);
                t.setUncaughtExceptionHandler((t1, e) -> logger.error("timer: throw error,thread:{},error msg:{}",t1.getName(),e));
                t.setName("-HashedTimerWheelInstance-");
                return t;
            }, 1, TimeUnit.SECONDS, 60);
        }

        public HashedWheelTimer getWheelTimer() {
            return wheelTimer;
        }

}
